1 ================================================================================
2 Windows APPLICATION: CSWebBrowserSuppressError Overview
3 ===============================================================================
4 /////////////////////////////////////////////////////////////////////////////
6 The sample demonstrates how to make WebBrowser suppress errors. The errors include
8 1. Calling Script Just In Time Debugger.
10 function CallDebugger() {
14 This could be disabled by the value of DisableJITDebugger in the key
15 HKCU\Software\Microsoft\Internet Explorer\Main.
17 Notice that to disable JIT debugger, the application has to be restarted.
19 2. Html element errors.
21 function CreateScriptError() {
22 throw ("Here is an error! ");
25 You can register the Document.Window.Error event and handle it.
27 Notice that Document.Window.Error event will only take effect when JITDebugger
30 3. Navigation error. Like the page does not exist(Http 404 error).
32 DWebBrowserEvents2 Interface designates an event sink interface that an application
33 must implement to receive event notifications from the underlying ActiveX control,
34 and there is a NavigateError Event in this interface. See
35 http://msdn.microsoft.com/en-us/library/aa768283(VS.85).aspx
37 4. Other errors, like permission is needed when clipboard is used in Javascript.
39 If you want to suppress all errors, you can set ScriptErrorsSuppressed to true. When
40 ScriptErrorsSuppressed is set to true, the WebBrowser control hides all its dialog
41 boxes that originate from the underlying ActiveX control, not just script errors.
42 Occasionally you might need to suppress script errors while displaying dialog boxes
43 such as those used for browser security settings and user login. In this case, set
44 ScriptErrorsSuppressed to false and suppress script errors in a handler for the
45 HtmlWindow.Error event.
47 ////////////////////////////////////////////////////////////////////////////////
52 Step1. Run CSWebBrowserSuppressError.exe.
54 Step2. Uncheck "Suppress JIT Debugger", and restart this application.
55 You can skip this step if the checkbox is already unchecked.
57 Step3. Make the top textbox empty, and click the button "Go". This operation will let
58 WebBrowser navigate to a build-in html with errors.
60 Step4. Click "Launch Debugger" in the page, you will see a dialog to launch JIT debugger
63 Step5. Check "Suppress JIT Debugger", and restart this application.
65 Step6. Make the top textbox empty, and click the button "Go".
67 Step7. Click "Launch Debugger" in the page, you will not see the dialog to launch JIT
71 Suppress html element errors
73 Step1. Run CSWebBrowserSuppressError.exe.
75 Step2. Check "Suppress JIT Debugger", and restart this application.
76 You can skip this step if the checkbox is already checked.
78 Step3. Make the top textbox empty, and click the button "Go". This operation will let
79 WebBrowser navigate to a build-in html with errors.
81 Step4. Uncheck "Suppress Html Element Errors".
83 Step5. Click "Script Error" in the page, you will see a WebPage error dialog.
85 Step6. Check "Suppress Html Element Errors".
87 Step7. Click "Script Error" in the page, you will not see the WebPage error dialog.
91 Handle navigation error
93 Step1. Run CSWebBrowserSuppressError.exe.
95 Step2. Uncheck "Suppress Navigation Error".
97 Step3. Type http://www.microsoft.com/NotExist.html the top textbox, and click the button "Go".
98 Microsoft.com will tell you that the page is not found.
100 Step4. Check "Suppress Navigation Error".
102 Step5. Type http://www.microsoft.com/NotExist.html the top textbox, and click the button "Go".
103 You will see the build-in HTTP404 html.
109 Step1. Run CSWebBrowserSuppressError.exe.
111 Step2. Make the top textbox empty, and click the button "Go". This operation will let
112 WebBrowser navigate to a build-in html with errors.
114 Step3. Uncheck "Suppress all dialog".
116 Step4. Click "Security Dialog" in the page, you will see a "Windows Security Warning" dialog.
118 Step5. Make the top textbox empty, and click the button "Go" again. Or refresh this page in the
121 Step6. Check "Suppress all dialog".
123 Step7. Click "Security Dialog" in the page, you will not see the "Windows Security Warning"
127 /////////////////////////////////////////////////////////////////////////////
130 1. Create html file Error.htm. This web page can create script error, security warning and
133 2. Design a class WebBrowserEx that inherits class System.Windows.Forms.WebBrowser. This
134 class supplies following features.
136 2.1. Disable JIT Debugger.
137 The static property DisableJITDebugger can get or set the value of "Disable Script
138 Debugger" in the key HKCU\Software\Microsoft\Internet Explorer\Main.
140 2.2. Suppress html element errors of document loaded in this browser.
141 Handle the window error event of document loaded in this browser.
143 2.3. Handle navigation error.
144 The interface DWebBrowserEvents2 designates an event sink interface that an application
145 must implement to receive event notifications from a WebBrowser control or from the
146 Windows Internet Explorer application. The event notifications include NavigateError
147 event that will be used in this application.
149 2.4 The class WebBrowser itself also has a Property ScriptErrorsSuppressed to hides all its
150 dialog boxes that originate from the underlying ActiveX control, not just script errors.
152 3. In the MainForm, handle the checkboxes CheckedChanged event to disable JIT debugger, suppress html
153 element errors and suppress all dialog.
155 It also registers the NavigateError event of WebBrowserEx. If "Suppress Navigation Error" is
156 checked and the http status code is 404, then navigate to the build-in 404.htm.
159 /////////////////////////////////////////////////////////////////////////////
161 http://msdn.microsoft.com/en-us/library/aa768283(VS.85).aspx
162 http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.scripterrorssuppressed.aspx
163 http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.createsink.aspx
164 /////////////////////////////////////////////////////////////////////////////